use serde::{Deserialize, Serialize};
use std::net::SocketAddr;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Config {
    pub server: ServerConfig,
    pub endpoints: Vec<EndpointConfig>,
    pub logging: LoggingConfig,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ServerConfig {
    pub address: SocketAddr,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct EndpointConfig {
    pub path: String,
    pub methods: Vec<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LoggingConfig {
    pub level: String,
    pub rotation: RotationConfig,
    pub directory: String,
    pub filename: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RotationConfig {
    pub strategy: String,
    pub max_size: String,
    pub max_files: usize,
}

impl Config {
    pub fn new() -> anyhow::Result<Self> {
        let settings = config::Config::builder()
            .add_source(config::File::with_name("config"))
            .build()?;

        settings.try_deserialize().map_err(Into::into)
    }
} 